package com.scj.vue3springboot.controller.sys;

import com.scj.vue3springboot.entity.SysRole;
import com.scj.vue3springboot.entity.vo.RoleMenuVo;
import com.scj.vue3springboot.service.SysRoleService;
import com.scj.vue3springboot.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ShiChaojie
 * @date 2023/10/16 15:09
 */
@Api("角色接口")
@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation("获取所有角色信息接口")
    @GetMapping("/findAllRoleInfo/{page}/{limit}")
    public Result findAllRoleInfo(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @ModelAttribute SysRole sysRole) {
        return sysRoleService.findAllUserInfo(page, limit, sysRole);
    }

    @ApiOperation("添加角色接口")
    @PostMapping("/addRole")
    public Result addRole(@RequestBody SysRole sysRole, @RequestHeader("token") String token) {
        return sysRoleService.addRole(sysRole, token);
    }

    @ApiOperation("修改角色接口")
    @PutMapping("/updateRole")
    public Result updateRole(@RequestBody SysRole sysRole, @RequestHeader("token") String token) {
        return sysRoleService.updateRole(sysRole, token);
    }

    @ApiOperation("删除角色接口")
    @DeleteMapping("/deleteRole/{roleId}")
    public Result deleteRole(@PathVariable Long roleId, @RequestHeader("token") String token) {
        return sysRoleService.deleteRole(roleId, token);
    }

    @ApiOperation("根据角色id查询所有菜单信息以及这个角色下有哪些菜单信息的接口")
    @GetMapping("/findAllRoleAndMenuRole/{roleId}")
    public Result findAllRoleAndMenuRole(@PathVariable Long roleId) {
        return sysRoleService.findAllRoleAndMenuRole(roleId);
    }

    @ApiOperation("根据角色ID设置菜单权限接口")
    @PostMapping("/addRoleMenu")
    public Result addRoleMenu(@RequestBody RoleMenuVo roleMenuVo) {
        return sysRoleService.addRoleMenu(roleMenuVo);
    }
}
